const Home = () => import('@/pages/Home') 
const Search = () => import('@/pages/Search')
const Register = () => import('@/pages/Register') 
const Detail = () => import('@/pages/Detail') 
const AddCartSuccess = () => import('@/pages/AddCartSuccess') 
const ShopCart = () => import('@/pages/ShopCart') 
const Trade = () => import('@/pages/Trade') 
const Pay = () => import('@/pages/Pay') 
const PaySuccess = () => import('@/pages/PaySuccess') 
const Center = () => import('@/pages/Center') 
const Myorder = () => import('@/pages/Center/Myorder') 
const GroupOrder = () => import('@/pages/Center/GroupOrder') 
export default [{
  path: '/home',
  component: Home
},
{
  name: 'search',
  path: '/search/:keyword?',
  component: Search,
  props(r) {
    return {
      id: r.params.keyword,
      name: r.query.keyword1
    }
  }
},
{
  name: 'login',
  path: '/login',
  component: () => import('@/pages/Login'),
  meta: {
    isHidden: true
  }
},
{
  path: '/register',
  component: Register,
  meta: {
    isHidden: true
  }
},
{
  path: '/detail/:skuId',
  component: Detail
},
{
  name: 'addcartsuccess',
  path: '/addcartsuccess/:skunum',
  component: AddCartSuccess,
  beforeEnter: (to,from, next) => {
    let skuNum = to.params.skunum
    let skuInfo = sessionStorage.getItem('skuInfo')
    if (skuNum && skuInfo) {
      next()
    } else {
      alert('您必须携带skuNum和skuInfo')
      next(false)
    }
  }
},
{
  path: '/shopcart',
  component: ShopCart,
},
{
  path: '/trade',
  component: Trade,
  beforeEnter: (to,from, next) => {
    if (from.path === '/shopcart') {
      next()
    } else {
      alert('请您从购物车页面跳转过来')
      next(false)
    }
  }
},
{
  path: '/pay',
  component: Pay,
  beforeEnter: (to, from, next) => {
    if (from.path === '/trade') {
      next()
    } else {
      alert('请您从交易页面跳转过来')
      next(false)
    }
  }
},
{
  path: '/paysuccess',
  component: PaySuccess,
  beforeEnter: (to, from, next) => {
    if (from.path === '/pay') {
      next()
    } else {
      alert('请您从支付页面跳转过来')
      next(false)
    }
  }
},
{
  path: '/center',
  component: Center,
  children: [
    {
      path: 'myorder',
      component: Myorder
    },
    {
      path: 'grouporder',
      component: GroupOrder
    },
    {
      path: '',
      redirect: '/center/myorder'
    }
  ]
},
{
  path: '/',
  redirect: '/home'
}]